﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;


namespace BloodBot
{
    public class Input
    {
        KeyboardState kState, oldkState;
        MouseState mState, oldmState;
        int vpW, vpH;

        public Input(int ViewportW, int ViewportH)
        {
            vpW = ViewportW;
            vpH = ViewportH;
        }
        
        #region Keyboard Properties

        public bool Forward()
        {
            return kState.IsKeyDown(Keys.W) || kState.IsKeyDown(Keys.Up); 
        }

        public bool Backward()
        {
            return kState.IsKeyDown(Keys.S) || kState.IsKeyDown(Keys.Down);
        }

        public bool Left()
        {
            return kState.IsKeyDown(Keys.A) || kState.IsKeyDown(Keys.Left);
        }

        public bool Right()
        {
            return kState.IsKeyDown(Keys.D) || kState.IsKeyDown(Keys.Right);
        }

        public bool FSwitch()
        {
            return (kState.IsKeyDown(Keys.F) && !oldkState.IsKeyDown(Keys.F));
        }

        public bool RSwitch()
        {
            return kState.IsKeyDown(Keys.R) && !oldkState.IsKeyDown(Keys.R);
        }

        public bool Escape()
        {
            return kState.IsKeyDown(Keys.Escape);
        }

        public bool Debug()
        {
            return kState.IsKeyDown(Keys.F12) && !oldkState.IsKeyDown(Keys.F12);
        }

        public bool BSwitch()
        {
            return kState.IsKeyDown(Keys.B) && !oldkState.IsKeyDown(Keys.B);
        }

        #endregion

        #region Mouse Properties
        
        public int MouseXDifference()
        {
            return (mState.X - oldmState.X);
            
        }

        public int MouseYDifference()
        {
            return (mState.Y - oldmState.Y);
        }

        public int MouseX()
        {   return mState.X;    }

        public int MouseY()
        {   return mState.Y;    }

        public bool MouseMoved()
        {
            return mState != oldmState;
        }

        public bool MouseRClickSwitch()
        {
            return (mState.RightButton == ButtonState.Pressed && 
                oldmState.RightButton != ButtonState.Pressed);
        }

        public bool MouseRClick()
        {
            return mState.RightButton == ButtonState.Pressed;
        }

        public bool MouseLClickSwitch()
        {
            return (mState.LeftButton == ButtonState.Pressed && 
                oldmState.LeftButton != ButtonState.Pressed);
        }

        public bool MouseLClick()
        {
            return mState.LeftButton == ButtonState.Pressed;
        }

        public void CenterMouse()
        {
            Mouse.SetPosition(vpW / 2, vpH / 2);
            //The oldmState must be set to center also, otherwise the camera will *Stick*
            oldmState = Mouse.GetState();
        }

        #endregion

        public void Update()
        {
            oldkState = kState;
            kState = Keyboard.GetState();
            oldmState = mState;
            mState = Mouse.GetState();
            
        }

    }
}
